import 'package:flutter/material.dart';
import 'package:hxdj/common/components/my_tap_widget.dart';
import 'package:hxdj/common/components/my_text.dart';
import 'package:hxdj/common/my_header_global.dart';
import 'package:hxdj/common/routers/navigator.dart';
import 'package:hxdj/home/home_viewmodel.dart';
import 'package:hxdj/home/order/order_item_page.dart';
import 'package:hxdj/home/order/order_page.dart';

class HomeOrderWidget extends StatelessWidget {

  final HomeViewModel viewModel;

  const HomeOrderWidget({super.key, required this.viewModel});

  @override
  Widget build(BuildContext context) {
    
    
    //header
    buildHeader() {
      return Container(
          padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.h),
          child: Row(children: [
            //标题
            Expanded(
              child: Container(
                alignment: Alignment.centerLeft,
                child: Column(
                  children: [
                    MyText("今日订单", textStyle: MyTextStyles.textBlackBold16),
                    MyBorder(
                        color: MyColours.appMain,
                        backgroundColor: MyColours.appMain,
                        radius: 1.5.h,
                        child: SizedBox(
                          width: 25.w,
                          height: 3.h,
                        ))
                  ],
                ),
              ),
            ),
            const Spacer(),

            //更多
            MyTapWidget(
              onTap: () {
                NavigatorUtils.push(context, OrderPage.routeName);
                // NavigatorUtils.push(context, RecommendTechnicianPage.routeName);
              },
              child: Row(
                children: [
                  //更多
                  MyText("更多订单", color: MyColours.color999999, fontSize: 12.sp),
                  //箭头
                  Container(
                      padding: EdgeInsets.only(left: 5.w),
                      child: MyImage(imageName: "ic_arrow_right", width: 6.w, height: 9.h)),
                ],
              ),
            ),
          ]));
    }

    return Container(
        decoration: BoxDecoration(
          color: MyColours.materialBg,
          //设置四周圆角 角度
          borderRadius: BorderRadius.circular(12.5.w),
        ),
        margin: EdgeInsets.symmetric(horizontal: 10.w, vertical: 5.h),
        child: Column(children: [
          // hedaer
          buildHeader(),
          viewModel.orderModels.isEmpty
              ? Container()
              : 
          Container(
              margin: EdgeInsets.only(bottom: 26.h),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: viewModel.orderModels.map((e) {
                  return Container(
                    margin: EdgeInsets.only(
                        left: 10.w, right: 10.w, top: (viewModel.orderModels.indexOf(e) == 0) ? 0 : 10.h),
                    child: MyBorder(
                      decoration: MyBorder.defaultDecoration,
                      child: OrderItem(orderModel: e),
                    ),
                  );
                }).toList(),
              ))
        ]));
  }
}
